package com.yygo.model;

import com.yygo.model.enums.CarType;

import javax.persistence.*;

/**
 * Created by tiansha on 2015/6/23.
 */
@Entity
@Table(name = "vehicle_model")
public class VehicleModel extends BaseObject {
    private static final long serialVersionUID = -7031880298545369556L;
    private Long id;
    private String name;
    private Long guidePrice;
    private VehicleSeries vehicleSeries;
    private CarType carType;
    private Long secondPrice;
    private boolean imported = false;

    public  VehicleModel() {}

    public VehicleModel(String name, Long price) {
        this.name = name;
        this.guidePrice = price;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(length = 100)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="guide_price")
    public Long getGuidePrice() {
        return guidePrice;
    }

    public void setGuidePrice(Long guidePrice) {
        this.guidePrice = guidePrice;
    }

    @ManyToOne
    @JoinColumn(name="series_id")
    public VehicleSeries getVehicleSeries() {
        return vehicleSeries;
    }

    public void setVehicleSeries(VehicleSeries vehicleSeries) {
        this.vehicleSeries = vehicleSeries;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "car_type", length = 20)
    public CarType getCarType() {
        return carType;
    }

    public void setCarType(CarType carType) {
        this.carType = carType;
    }

    @Column(name="second_price")
    public Long getSecondPrice() {
        return secondPrice;
    }

    public void setSecondPrice(Long secondPrice) {
        this.secondPrice = secondPrice;
    }

    @Column(name="imported")
    public boolean isImported() {
        return imported;
    }

    public void setImported(boolean imported) {
        this.imported = imported;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        VehicleModel vehicleModel = (VehicleModel) o;

        if (name.equals(vehicleModel.name)) {
            return true;
        }

        return false;
    }

    public int hashCode() {
        int result;
        result = (name != null ? name.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "Vehicle Model{" +
                "brand='" + vehicleSeries.getVehicleBrand().getBrand() +
                ", series='" + vehicleSeries.getName() +
                ", model='" + name +
                '}';
    }
}
